<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>（总分）总经理审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui-v2.5.6/css/layui.css" media="all">
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/res/js/util.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <!--模糊搜索区域-->
    <link rel="stylesheet" href="../../css/oksub.css">
</head>
<body>

<div class="ok-body">
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search">
            <input class="layui-input" placeholder="开始日期" autocomplete="off" id="startTime" name="startTime">
            <input class="layui-input" placeholder="截止日期" autocomplete="off" id="endTime" name="endTime">
            <input class="layui-input" placeholder="请输入采购人" autocomplete="off" name="operator">
            <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<input type="hidden" name="status" id="status">
<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs" lay-event="ImmPurchaseDeatis">查询订单详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="HqReview">查询审核详情</a>
</script>
<script type="text/html" id="barDemo">
    {{# if(returnUser()){ }}
        {{# if(authorization("audit:managerAudit") ){ }}
            {{# if(d.isva<60){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('60')" lay-event="audit" >审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else if(authorization("audit:sellAudit")){ }}
            {{# if(d.isva<50){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('50')" lay-event="audit" >审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
         {{# } }}
    {{# }else{ }}
        {{# if(authorization("audit:managerAudit")){ }}
            {{# if(d.isva<40 ){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('40')" lay-event="audit" id="audit">审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else if(authorization("audit:purchaseAudit")){ }}
            {{# if(d.isva<30){ }}
            <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('30')" lay-event="audit" id="audit">审核</a>
            {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# } }}
    {{# } }}

</script>

<script type="text/html" id="img">
    <img src="/img/upload/{{d.proImg}}" alt="图片" width="50" height="50" onclick="showBig(this)"/>
</script>
<script type="text/javascript" src="/res/layui-v2.5.6/layui.js"></script>
<script>
    var openIndex = null;
    var table = null;
    var laydate = null;
    layui.use(['table', 'laydate'], function () {
        table = layui.table;
        laydate = layui.laydate;
        let form = layui.form;


        let roleTable = table.render({
            method:"POST",
            elem: '#test'
            , url: '/immPurchase/showList'
            // , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '分公司采购计划单数据表'
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,totalRow: true  //开启合计
            ,height:600
            , cols: [[
                // {type: 'checkbox', fixed: 'left'}
                {field: 'purchaseId', title: '序号', fixed: 'left', type: 'numbers',unresize: true, sort: 'true', totalRowText: '合计'}
                , {field: 'immName', title: '分公司名称'}
                , {field: 'purchaseCount', title: '采购总数量',align:"center", totalRow: true}
                , {field: 'purchaseMoney', title: '采购总金额',align:"center", totalRow: true}
                , {field: 'operator', title: '采购人', align:"center"}
                , {field: 'purchaseTime', title: '采购时间', align:"center"}
                , {field: 'isva', title: '审核状态',width: 300,align:"center", unresize : true, templet:function(d){
                        if(d.isva == '20'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">待分公司采购经理审核</p>';
                        }else if(d.isva == '30'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">待审核</p>';
                        }else if(d.isva == '31'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司采购经理不通过</p>';
                        }else if(d.isva == '40'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司总经理通过,等待总公司销售经理审核</p>';
                        }else if(d.isva == '41'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司总经理不通过</p>';
                        }else if(d.isva == '50'){
                            if(returnUser()){
                                return '<p class="layui-btn layui-btn-danger layui-btn-xs">待审核</p>';
                            }else{
                                return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司销售经理通过,等待总公司总经理审核</p>';
                            }
                        }else if(d.isva == '51'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司销售经理不通过</p>';
                        }else if(d.isva == '60'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过,完成审核</p>';
                        }else if(d.isva == '61'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>';
                        }else if(d.isva == '65'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">已提交退货申请</p>';
                        }else if(d.isva == '66'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理退货申请通过</p>';
                        }else if(d.isva == '67'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司退货申请不通过</p>';
                        }else if(d.isva == '68'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">提交财务申请</p>';
                        }else if(d.isva == '80'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司财务通过</p>';
                        }else if(d.isva == '81'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司财务不通过</p>';
                        }else if(d.isva == '90'){
                            return '<p class="layui-btn layui-btn-normal layui-btn-xs">未入库</p>';
                        }else if(d.isva == '91'){
                            return '<p class="layui-btn layui-btn-normal layui-btn-xs">已入库</p>';
                        }
                    }}
                , {field: 'sort', title: '排序', align:"center"}
                , {field: 'remark', title: '备注', align:"center",width: 200}
                , {fixed: 'right', title: '查询信息', width: 210, toolbar: '#barDemo2',align:"center"}
                , {fixed: 'right', title: '操作', width: 180, toolbar: '#barDemo', align:"center"}
            ]]
            , page: true
            , limits: [10, 20, 50, 100, 200, 500,1000]
            , id: 'test'
            ,where: {  //判断是分公司总经理还是总公司总经理 过滤状态
                isva: returnUser() ? "0,10,20,30,40" :"0,10"
            }
        });

        //查询条件
        form.on("submit(search)", function (data) {
            console.info(data)
            roleTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            console.log("0000")
            return false;
        });


        //日期时间选择器
        laydate.render({
            elem: "#startTime",
            theme: 'molv',
            type: "datetime"});
        laydate.render({
            elem: "#endTime",
            type: "datetime",
            theme: 'molv'
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(data);
            if(obj.event === "ImmPurchaseDeatis"){
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['85%', '85%'], //宽高
                    title: '采购明细',
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/immPurchase/immPurchaseDeatis.html?id=' + id,
                });
            }else if(obj.event === "HqReview"){
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['85%', '85%'], //宽高
                    title: '审核记录',
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }else if(obj.event === 'audit'){
                console.info(data)
                var id = data.purchaseId;
                //将采购单id赋值
                $("#purchaseId").val(id);
                //获取所点击审核的人的权限
                let status = $("#status").val();
                console.info($("#status").val());
                openIndex = layui.layer.open({
                    type: 2,
                    area: ['55%', '60%'], //宽高
                    title: '审核信息',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    // content:  $("#popUpdateTest"),
                    content:`/ok-admin/pages/audit/auditForm.html?id=${id}&status=${status}`
                });
            }
        });
        //审核请求
        window.openAudit = function (status) {
            $("#status").val(status);
        }
    });





    function close(obj) {
        layer.close(openIndex);
    }


    /**
     * 关闭弹出层
     */
    function closeOpen(msg) {
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg, {time: 1000,icon:1}, function () {
            table.reload("test");//刷新表格
        })
    }

    /**
     * 错误提示 关闭弹出层
     */
    function errorCloseOpen(msg){
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg,{time:3000,icon:2},function(){
            table.reload("test");
            //window.location.reload(true);
        });
    }

    function showBig(obj) {
        $("#imgDiv").fadeToggle(1000);//渐隐
        $("#imgDiv_img").prop("src", obj.src);
    }

</script>

<div id="imgDiv" style="display:none; position:absolute;left:20%;top:10%">
    <img src="" id="imgDiv_img" width="50%" heigth="50%" onclick="showBig(this)"/>
</div>
</body>
</html>